
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 12/16/2011 19:36:04
-- Generated from EDMX file: C:\Users\Alistair\Documents\NMRplusSourceCode\NMRplus\IdeaNMR.Web.Core\IdeaNMRdb.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [IdeaNMRDevData];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_ExperimentSample]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Experiments] DROP CONSTRAINT [FK_ExperimentSample];
GO
IF OBJECT_ID(N'[dbo].[FK_ExperimentUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Experiments] DROP CONSTRAINT [FK_ExperimentUser];
GO
IF OBJECT_ID(N'[dbo].[FK_ExperimentSpectrometer]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Experiments] DROP CONSTRAINT [FK_ExperimentSpectrometer];
GO
IF OBJECT_ID(N'[dbo].[FK_NumberedAuthorUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[NumberedAuthors] DROP CONSTRAINT [FK_NumberedAuthorUser];
GO
IF OBJECT_ID(N'[dbo].[FK_BaseEntryNumberedAuthor]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[NumberedAuthors] DROP CONSTRAINT [FK_BaseEntryNumberedAuthor];
GO
IF OBJECT_ID(N'[dbo].[FK_BaseObjectBaseObject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects] DROP CONSTRAINT [FK_BaseObjectBaseObject];
GO
IF OBJECT_ID(N'[dbo].[FK_UserBaseObject_JunkCounter_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserBaseObject_JunkCounter] DROP CONSTRAINT [FK_UserBaseObject_JunkCounter_User];
GO
IF OBJECT_ID(N'[dbo].[FK_UserBaseObject_JunkCounter_BaseObject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserBaseObject_JunkCounter] DROP CONSTRAINT [FK_UserBaseObject_JunkCounter_BaseObject];
GO
IF OBJECT_ID(N'[dbo].[FK_UserSample]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_Sample] DROP CONSTRAINT [FK_UserSample];
GO
IF OBJECT_ID(N'[dbo].[FK_UserSpectrometer]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_Spectrometer] DROP CONSTRAINT [FK_UserSpectrometer];
GO
IF OBJECT_ID(N'[dbo].[FK_PulseProgramExperiment]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Experiments] DROP CONSTRAINT [FK_PulseProgramExperiment];
GO
IF OBJECT_ID(N'[dbo].[FK_NamedComponentAuxComponent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[NamedComponents] DROP CONSTRAINT [FK_NamedComponentAuxComponent];
GO
IF OBJECT_ID(N'[dbo].[FK_NamedComponentPulseProgram]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[NamedComponents] DROP CONSTRAINT [FK_NamedComponentPulseProgram];
GO
IF OBJECT_ID(N'[dbo].[FK_HardObject_inherits_BaseObject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_HardObject] DROP CONSTRAINT [FK_HardObject_inherits_BaseObject];
GO
IF OBJECT_ID(N'[dbo].[FK_Sample_inherits_HardObject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_Sample] DROP CONSTRAINT [FK_Sample_inherits_HardObject];
GO
IF OBJECT_ID(N'[dbo].[FK_Spectrometer_inherits_HardObject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_Spectrometer] DROP CONSTRAINT [FK_Spectrometer_inherits_HardObject];
GO
IF OBJECT_ID(N'[dbo].[FK_NMRObject_inherits_BaseObject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_NMRObject] DROP CONSTRAINT [FK_NMRObject_inherits_BaseObject];
GO
IF OBJECT_ID(N'[dbo].[FK_PulseProgram_inherits_NMRObject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_PulseProgram] DROP CONSTRAINT [FK_PulseProgram_inherits_NMRObject];
GO
IF OBJECT_ID(N'[dbo].[FK_AuxComponent_inherits_NMRObject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_AuxComponent] DROP CONSTRAINT [FK_AuxComponent_inherits_NMRObject];
GO
IF OBJECT_ID(N'[dbo].[FK_Script_inherits_AuxComponent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_Script] DROP CONSTRAINT [FK_Script_inherits_AuxComponent];
GO
IF OBJECT_ID(N'[dbo].[FK_Wave_inherits_AuxComponent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_Wave] DROP CONSTRAINT [FK_Wave_inherits_AuxComponent];
GO
IF OBJECT_ID(N'[dbo].[FK_Cpd_inherits_AuxComponent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_Cpd] DROP CONSTRAINT [FK_Cpd_inherits_AuxComponent];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Users]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Users];
GO
IF OBJECT_ID(N'[dbo].[Experiments]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Experiments];
GO
IF OBJECT_ID(N'[dbo].[NumberedAuthors]', 'U') IS NOT NULL
    DROP TABLE [dbo].[NumberedAuthors];
GO
IF OBJECT_ID(N'[dbo].[NamedComponents]', 'U') IS NOT NULL
    DROP TABLE [dbo].[NamedComponents];
GO
IF OBJECT_ID(N'[dbo].[BaseObjects]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseObjects];
GO
IF OBJECT_ID(N'[dbo].[BaseObjects_HardObject]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseObjects_HardObject];
GO
IF OBJECT_ID(N'[dbo].[BaseObjects_Sample]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseObjects_Sample];
GO
IF OBJECT_ID(N'[dbo].[BaseObjects_Spectrometer]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseObjects_Spectrometer];
GO
IF OBJECT_ID(N'[dbo].[BaseObjects_NMRObject]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseObjects_NMRObject];
GO
IF OBJECT_ID(N'[dbo].[BaseObjects_PulseProgram]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseObjects_PulseProgram];
GO
IF OBJECT_ID(N'[dbo].[BaseObjects_AuxComponent]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseObjects_AuxComponent];
GO
IF OBJECT_ID(N'[dbo].[BaseObjects_Script]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseObjects_Script];
GO
IF OBJECT_ID(N'[dbo].[BaseObjects_Wave]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseObjects_Wave];
GO
IF OBJECT_ID(N'[dbo].[BaseObjects_Cpd]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseObjects_Cpd];
GO
IF OBJECT_ID(N'[dbo].[UserBaseObject_JunkCounter]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserBaseObject_JunkCounter];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Users'
CREATE TABLE [dbo].[Users] (
    [Username] nvarchar(128)  NOT NULL,
    [Firstname] nvarchar(50)  NULL,
    [Middlename] nvarchar(50)  NULL,
    [Lastname] nvarchar(50)  NULL,
    [Datetime] datetime  NOT NULL
);
GO

-- Creating table 'Experiments'
CREATE TABLE [dbo].[Experiments] (
    [Id] uniqueidentifier  NOT NULL,
    [Remark] nvarchar(max)  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Datetime] datetime  NOT NULL,
    [Script] nvarchar(max)  NOT NULL,
    [Parameters] nvarchar(2000)  NOT NULL,
    [Sample_Id] uniqueidentifier  NOT NULL,
    [User_Username] nvarchar(128)  NOT NULL,
    [Spectrometer_Id] uniqueidentifier  NOT NULL,
    [PulseProgram_Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'NumberedAuthors'
CREATE TABLE [dbo].[NumberedAuthors] (
    [Index] int  NOT NULL,
    [Id] uniqueidentifier  NOT NULL,
    [User_Username] nvarchar(128)  NOT NULL,
    [NMRObject_Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'NamedComponents'
CREATE TABLE [dbo].[NamedComponents] (
    [Id] uniqueidentifier  NOT NULL,
    [Identifier] nvarchar(50)  NOT NULL,
    [AuxComponent_Id] uniqueidentifier  NOT NULL,
    [PulseProgram_Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseObjects'
CREATE TABLE [dbo].[BaseObjects] (
    [Id] uniqueidentifier  NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Datetime] datetime  NOT NULL,
    [Info] nvarchar(2000)  NOT NULL,
    [Script] nvarchar(max)  NOT NULL,
    [VersionInfo] nvarchar(2000)  NOT NULL,
    [IsDraft] bit  NOT NULL,
    [IsPrivate] bit  NOT NULL,
    [FirstVersion_Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseObjects_HardObject'
CREATE TABLE [dbo].[BaseObjects_HardObject] (
    [ContactPerson] nvarchar(128)  NOT NULL,
    [ContactEmail] nvarchar(max)  NOT NULL,
    [Location] nvarchar(50)  NOT NULL,
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseObjects_Sample'
CREATE TABLE [dbo].[BaseObjects_Sample] (
    [Buffer] nvarchar(max)  NOT NULL,
    [Labeling] nvarchar(max)  NOT NULL,
    [Id] uniqueidentifier  NOT NULL,
    [User_Username] nvarchar(128)  NOT NULL
);
GO

-- Creating table 'BaseObjects_Spectrometer'
CREATE TABLE [dbo].[BaseObjects_Spectrometer] (
    [Frequency] float  NOT NULL,
    [Id] uniqueidentifier  NOT NULL,
    [User_Username] nvarchar(128)  NOT NULL
);
GO

-- Creating table 'BaseObjects_NMRObject'
CREATE TABLE [dbo].[BaseObjects_NMRObject] (
    [Content] nvarchar(max)  NOT NULL,
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseObjects_PulseProgram'
CREATE TABLE [dbo].[BaseObjects_PulseProgram] (
    [Dimensionality] tinyint  NOT NULL,
    [Type] nvarchar(50)  NOT NULL,
    [Analytics] nvarchar(max)  NOT NULL,
    [SpinachMacro] nvarchar(max)  NULL,
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseObjects_AuxComponent'
CREATE TABLE [dbo].[BaseObjects_AuxComponent] (
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseObjects_Script'
CREATE TABLE [dbo].[BaseObjects_Script] (
    [Type] nvarchar(50)  NOT NULL,
    [IsIncludable] bit  NOT NULL,
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseObjects_Wave'
CREATE TABLE [dbo].[BaseObjects_Wave] (
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseObjects_Cpd'
CREATE TABLE [dbo].[BaseObjects_Cpd] (
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'UserBaseObject_JunkCounter'
CREATE TABLE [dbo].[UserBaseObject_JunkCounter] (
    [JunkVoters_Username] nvarchar(128)  NOT NULL,
    [JunkVotes_Id] uniqueidentifier  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Username] in table 'Users'
ALTER TABLE [dbo].[Users]
ADD CONSTRAINT [PK_Users]
    PRIMARY KEY CLUSTERED ([Username] ASC);
GO

-- Creating primary key on [Id] in table 'Experiments'
ALTER TABLE [dbo].[Experiments]
ADD CONSTRAINT [PK_Experiments]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'NumberedAuthors'
ALTER TABLE [dbo].[NumberedAuthors]
ADD CONSTRAINT [PK_NumberedAuthors]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'NamedComponents'
ALTER TABLE [dbo].[NamedComponents]
ADD CONSTRAINT [PK_NamedComponents]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseObjects'
ALTER TABLE [dbo].[BaseObjects]
ADD CONSTRAINT [PK_BaseObjects]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseObjects_HardObject'
ALTER TABLE [dbo].[BaseObjects_HardObject]
ADD CONSTRAINT [PK_BaseObjects_HardObject]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseObjects_Sample'
ALTER TABLE [dbo].[BaseObjects_Sample]
ADD CONSTRAINT [PK_BaseObjects_Sample]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseObjects_Spectrometer'
ALTER TABLE [dbo].[BaseObjects_Spectrometer]
ADD CONSTRAINT [PK_BaseObjects_Spectrometer]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseObjects_NMRObject'
ALTER TABLE [dbo].[BaseObjects_NMRObject]
ADD CONSTRAINT [PK_BaseObjects_NMRObject]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseObjects_PulseProgram'
ALTER TABLE [dbo].[BaseObjects_PulseProgram]
ADD CONSTRAINT [PK_BaseObjects_PulseProgram]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseObjects_AuxComponent'
ALTER TABLE [dbo].[BaseObjects_AuxComponent]
ADD CONSTRAINT [PK_BaseObjects_AuxComponent]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseObjects_Script'
ALTER TABLE [dbo].[BaseObjects_Script]
ADD CONSTRAINT [PK_BaseObjects_Script]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseObjects_Wave'
ALTER TABLE [dbo].[BaseObjects_Wave]
ADD CONSTRAINT [PK_BaseObjects_Wave]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseObjects_Cpd'
ALTER TABLE [dbo].[BaseObjects_Cpd]
ADD CONSTRAINT [PK_BaseObjects_Cpd]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [JunkVoters_Username], [JunkVotes_Id] in table 'UserBaseObject_JunkCounter'
ALTER TABLE [dbo].[UserBaseObject_JunkCounter]
ADD CONSTRAINT [PK_UserBaseObject_JunkCounter]
    PRIMARY KEY NONCLUSTERED ([JunkVoters_Username], [JunkVotes_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Sample_Id] in table 'Experiments'
ALTER TABLE [dbo].[Experiments]
ADD CONSTRAINT [FK_ExperimentSample]
    FOREIGN KEY ([Sample_Id])
    REFERENCES [dbo].[BaseObjects_Sample]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ExperimentSample'
CREATE INDEX [IX_FK_ExperimentSample]
ON [dbo].[Experiments]
    ([Sample_Id]);
GO

-- Creating foreign key on [User_Username] in table 'Experiments'
ALTER TABLE [dbo].[Experiments]
ADD CONSTRAINT [FK_ExperimentUser]
    FOREIGN KEY ([User_Username])
    REFERENCES [dbo].[Users]
        ([Username])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ExperimentUser'
CREATE INDEX [IX_FK_ExperimentUser]
ON [dbo].[Experiments]
    ([User_Username]);
GO

-- Creating foreign key on [Spectrometer_Id] in table 'Experiments'
ALTER TABLE [dbo].[Experiments]
ADD CONSTRAINT [FK_ExperimentSpectrometer]
    FOREIGN KEY ([Spectrometer_Id])
    REFERENCES [dbo].[BaseObjects_Spectrometer]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ExperimentSpectrometer'
CREATE INDEX [IX_FK_ExperimentSpectrometer]
ON [dbo].[Experiments]
    ([Spectrometer_Id]);
GO

-- Creating foreign key on [User_Username] in table 'NumberedAuthors'
ALTER TABLE [dbo].[NumberedAuthors]
ADD CONSTRAINT [FK_NumberedAuthorUser]
    FOREIGN KEY ([User_Username])
    REFERENCES [dbo].[Users]
        ([Username])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_NumberedAuthorUser'
CREATE INDEX [IX_FK_NumberedAuthorUser]
ON [dbo].[NumberedAuthors]
    ([User_Username]);
GO

-- Creating foreign key on [NMRObject_Id] in table 'NumberedAuthors'
ALTER TABLE [dbo].[NumberedAuthors]
ADD CONSTRAINT [FK_BaseEntryNumberedAuthor]
    FOREIGN KEY ([NMRObject_Id])
    REFERENCES [dbo].[BaseObjects_NMRObject]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BaseEntryNumberedAuthor'
CREATE INDEX [IX_FK_BaseEntryNumberedAuthor]
ON [dbo].[NumberedAuthors]
    ([NMRObject_Id]);
GO

-- Creating foreign key on [FirstVersion_Id] in table 'BaseObjects'
ALTER TABLE [dbo].[BaseObjects]
ADD CONSTRAINT [FK_BaseObjectBaseObject]
    FOREIGN KEY ([FirstVersion_Id])
    REFERENCES [dbo].[BaseObjects]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BaseObjectBaseObject'
CREATE INDEX [IX_FK_BaseObjectBaseObject]
ON [dbo].[BaseObjects]
    ([FirstVersion_Id]);
GO

-- Creating foreign key on [JunkVoters_Username] in table 'UserBaseObject_JunkCounter'
ALTER TABLE [dbo].[UserBaseObject_JunkCounter]
ADD CONSTRAINT [FK_UserBaseObject_JunkCounter_User]
    FOREIGN KEY ([JunkVoters_Username])
    REFERENCES [dbo].[Users]
        ([Username])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [JunkVotes_Id] in table 'UserBaseObject_JunkCounter'
ALTER TABLE [dbo].[UserBaseObject_JunkCounter]
ADD CONSTRAINT [FK_UserBaseObject_JunkCounter_BaseObject]
    FOREIGN KEY ([JunkVotes_Id])
    REFERENCES [dbo].[BaseObjects]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserBaseObject_JunkCounter_BaseObject'
CREATE INDEX [IX_FK_UserBaseObject_JunkCounter_BaseObject]
ON [dbo].[UserBaseObject_JunkCounter]
    ([JunkVotes_Id]);
GO

-- Creating foreign key on [User_Username] in table 'BaseObjects_Sample'
ALTER TABLE [dbo].[BaseObjects_Sample]
ADD CONSTRAINT [FK_UserSample]
    FOREIGN KEY ([User_Username])
    REFERENCES [dbo].[Users]
        ([Username])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserSample'
CREATE INDEX [IX_FK_UserSample]
ON [dbo].[BaseObjects_Sample]
    ([User_Username]);
GO

-- Creating foreign key on [User_Username] in table 'BaseObjects_Spectrometer'
ALTER TABLE [dbo].[BaseObjects_Spectrometer]
ADD CONSTRAINT [FK_UserSpectrometer]
    FOREIGN KEY ([User_Username])
    REFERENCES [dbo].[Users]
        ([Username])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserSpectrometer'
CREATE INDEX [IX_FK_UserSpectrometer]
ON [dbo].[BaseObjects_Spectrometer]
    ([User_Username]);
GO

-- Creating foreign key on [PulseProgram_Id] in table 'Experiments'
ALTER TABLE [dbo].[Experiments]
ADD CONSTRAINT [FK_PulseProgramExperiment]
    FOREIGN KEY ([PulseProgram_Id])
    REFERENCES [dbo].[BaseObjects_PulseProgram]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PulseProgramExperiment'
CREATE INDEX [IX_FK_PulseProgramExperiment]
ON [dbo].[Experiments]
    ([PulseProgram_Id]);
GO

-- Creating foreign key on [AuxComponent_Id] in table 'NamedComponents'
ALTER TABLE [dbo].[NamedComponents]
ADD CONSTRAINT [FK_NamedComponentAuxComponent]
    FOREIGN KEY ([AuxComponent_Id])
    REFERENCES [dbo].[BaseObjects_AuxComponent]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_NamedComponentAuxComponent'
CREATE INDEX [IX_FK_NamedComponentAuxComponent]
ON [dbo].[NamedComponents]
    ([AuxComponent_Id]);
GO

-- Creating foreign key on [PulseProgram_Id] in table 'NamedComponents'
ALTER TABLE [dbo].[NamedComponents]
ADD CONSTRAINT [FK_NamedComponentPulseProgram]
    FOREIGN KEY ([PulseProgram_Id])
    REFERENCES [dbo].[BaseObjects_PulseProgram]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_NamedComponentPulseProgram'
CREATE INDEX [IX_FK_NamedComponentPulseProgram]
ON [dbo].[NamedComponents]
    ([PulseProgram_Id]);
GO

-- Creating foreign key on [Id] in table 'BaseObjects_HardObject'
ALTER TABLE [dbo].[BaseObjects_HardObject]
ADD CONSTRAINT [FK_HardObject_inherits_BaseObject]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseObjects]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseObjects_Sample'
ALTER TABLE [dbo].[BaseObjects_Sample]
ADD CONSTRAINT [FK_Sample_inherits_HardObject]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseObjects_HardObject]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseObjects_Spectrometer'
ALTER TABLE [dbo].[BaseObjects_Spectrometer]
ADD CONSTRAINT [FK_Spectrometer_inherits_HardObject]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseObjects_HardObject]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseObjects_NMRObject'
ALTER TABLE [dbo].[BaseObjects_NMRObject]
ADD CONSTRAINT [FK_NMRObject_inherits_BaseObject]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseObjects]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseObjects_PulseProgram'
ALTER TABLE [dbo].[BaseObjects_PulseProgram]
ADD CONSTRAINT [FK_PulseProgram_inherits_NMRObject]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseObjects_NMRObject]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseObjects_AuxComponent'
ALTER TABLE [dbo].[BaseObjects_AuxComponent]
ADD CONSTRAINT [FK_AuxComponent_inherits_NMRObject]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseObjects_NMRObject]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseObjects_Script'
ALTER TABLE [dbo].[BaseObjects_Script]
ADD CONSTRAINT [FK_Script_inherits_AuxComponent]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseObjects_AuxComponent]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseObjects_Wave'
ALTER TABLE [dbo].[BaseObjects_Wave]
ADD CONSTRAINT [FK_Wave_inherits_AuxComponent]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseObjects_AuxComponent]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseObjects_Cpd'
ALTER TABLE [dbo].[BaseObjects_Cpd]
ADD CONSTRAINT [FK_Cpd_inherits_AuxComponent]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseObjects_AuxComponent]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------